package ${groupId}.controller.system.resource;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import ${groupId}.dal.mybatis.model.SysResource;
import ${groupId}.service.system.resource.SysResourceService;
import ${groupId}.service.system.resource.dto.SysResourceAddItemReqDto;
import ${groupId}.service.system.resource.dto.SysResourceAddItemRspDto;
import ${groupId}.service.system.resource.dto.SysResourceTree;
import ${groupId}.service.system.resource.dto.SysResourceUpdateItemReqDto;
import com.system.core.controller.ControllerBase;
import com.system.core.results.ResultBase;
import io.swagger.v3.oas.annotations.Hidden;

@Controller
@RequestMapping("boss/sys_resource")
@Hidden
public class SysResourceController extends ControllerBase {
	@Autowired
	private SysResourceService sysResourceService;
	
	@RequiresPermissions("resource_topage")
	@RequestMapping(value = "to_page",method = RequestMethod.GET)
	public String toPage() {
		return "/system/resource/sysResource-list";
	}
	
	@RequestMapping(value = "tree_data_source",method = RequestMethod.POST)
	@ResponseBody
	public List<SysResourceTree> treeDataSourceBind(){
		return sysResourceService.getMenusByParentId(0);
	}
	
	@RequestMapping(value = "get_by_pk",method = RequestMethod.POST)
	@ResponseBody
	public SysResource sysResourceGetByPrimaryKey(SysResource sysResource){
		return sysResourceService.sysResourceGetByPrimaryKey(sysResource);
	}
	
	@RequestMapping(value = "add_item",method = RequestMethod.POST)
	@ResponseBody
	public SysResourceAddItemRspDto sysResourceAddItem(@Validated SysResourceAddItemReqDto sysResourceAddItemReqDto) {
		return sysResourceService.sysResourceSave(sysResourceAddItemReqDto);
	}
	
	@RequestMapping(value = "update_item",method = RequestMethod.POST)
	@ResponseBody
	public ResultBase sysResourceUpdateItem(@Validated SysResourceUpdateItemReqDto sysResourceUpdateItemReqDto) {
		sysResourceUpdateItemReqDto.setParentResourceId(null);
		return sysResourceService.sysResourceUpdateByPrimaryKey(sysResourceUpdateItemReqDto);
	}
	
	@RequestMapping(value = "delete_item",method = RequestMethod.POST)
	@ResponseBody
	public ResultBase sysResourceDeleteItem(@RequestBody List<Long> keys) {
		return sysResourceService.sysResourceDeleteByPrimaryKey(keys);
	}
}
